home *** CD-ROM | disk | FTP | other *** search
- /* TNReceive.c -- XCMD copy 3270 screen into a global
- copyright 1989 Cornell University
- */
-
-
- #include <Types.h>
- #include <Memory.h>
- #include <Devices.h>
- #include <HyperXCmd.h>
- #include <Errors.h>
-
- #include <OSUtils.h>
-
- #include <String.h>
-
- #include "TNdrvr.h"
-
-
- pascal void debugger() extern 0xA9FF;
-
- extern long mystrtolong();
-
- pascal void TNReceive(hycp)
- XCmdPtr hycp;
- {
- CntrlParam drvpb;
- long * args;
- Str255 pstr;
- char * bufptr;
- Handle strhand;
- int length;
-
- if (hycp->paramCount != 2) {
- sethand(&hycp->returnValue, "TNReceive TNscreen,aglobal: need 2 arguments, aglobal quoted");
- return;
- }
-
- /* reformat buf ptr from string to ptr */
- #ifdef HYPE
- /* HyperCard 1.2.5 StrToLong no longer works here! */
- HLock((Handle) hycp->params[0]);
- ZeroToPas(hycp, *hycp->params[0], (StringPtr) &pstr[0]);
- HUnlock((Handle) hycp->params[0]);
-
- bufptr = (char *) StrToLong(hycp, (Str31 *) &pstr[0]);
- #else
- bufptr = (char *) mystrtolong(*hycp->params[0]);
- #endif
-
- /* dump whole screen buffer into a handle */
- if ((strhand = NewHandle((Size) HTNI_BUFSIZE)) == (Handle) 0L) {
- sethand(&hycp->returnValue, "Out of memory");
- return;
- }
- HLock(strhand);
- length = screendump(bufptr, bufptr, *strhand, 1920);
- HUnlock(strhand);
-
- *( ((char *) * strhand) + length) = 0; /* terminate with a null */
-
- /* set the global given as an arg to the handle's contents */
- HLock((Handle) hycp->params[1]);
- ZeroToPas(hycp, (char *) *hycp->params[1], &pstr[0]);
- HUnlock((Handle) hycp->params[1]);
-
-
- SetGlobal(hycp, &pstr[0], strhand);
- DisposHandle(strhand);
-
- if (hycp->result) {
- sethand(&hycp->returnValue, "Can't set aglobal");
- return;
- }
- }
-
-
- /* copy whole screen from scr_map format into a buffer, returning count copied
- target buffer must have (SCREEN_SIZE + COL_SIZE) bytes minimum
- includes all spaces
- */
-
- screendump(bufp, screenp, destarr, count)
- unsigned char * bufp; /* points at beginning of scr_map */
- unsigned char * screenp; /* points into scr_map to read from */
- unsigned char * destarr; /* points to dest to write into */
- int count; /* scrp + count -> last char to copy, exclusive */
- {
- register unsigned char * srcp = screenp;
- register unsigned char * destp = destarr;
- register unsigned char * endp = screenp + count; /* stake out the excluded end */
- register unsigned char thechar;
- unsigned char * lineend; /* really beginning of next line */
- register int skiponzero; /* # of good chars left in line */
- int firsttime = true; /* skip CR first time through loop */
-
- /* set up the skiponzero var for entry into the loop */
- lineend = bufp + ((((srcp - bufp) / ROW_SIZE)) * ROW_SIZE);
- /* set up lineend, which will point to beginning of next line */
- skiponzero = 1;
-
- while (true) {
- if (--skiponzero == 0) {
- if (firsttime)
- firsttime = false;
- else {
- *destp++ = CR; /* insert a CR for line end */
- srcp = lineend; /* set srcp forward */
- if (srcp >= endp)
- /* quit when we've done the work */
- break;
- }
-
- lineend += ROW_SIZE;
-
- skiponzero = ROW_SIZE;
- }
- if (srcp >= endp)
- /* quit when we've done the work */
- break;
-
- /* copy */
- if (((thechar = *srcp++) == (unsigned char) 0xFF) || (thechar < ATTR))
- /* use space for nulls and attributes */
- *destp++ = ' ';
- else
- *destp++ = thechar;
- }
- return(destp - destarr); /* return length */
- }
-
- sethand(thand, str)
- Handle * thand;
- char * str;
- {
- if (*thand == NULL) {
- *thand = NewHandle((Size) 0);
- }
- SetHandleSize(*thand, (long) (strlen(str) + 1));
- strcpy(**thand, str);
- }
-
-
- long mystrtolong(strp)
- unsigned char * strp;
- {
- long retval;
- char negate = 0;
-
- retval = 0;
- if (*strp == '-') {
- negate = 1;
- strp++;
- }
- while (*strp) {
- retval = (long) (retval * 10) + (long) (*strp - '0');
- strp++;
- }
- if (negate)
- retval = (long) -retval;
- return(retval);
- }
-
-
-
-
- #include <XCmdGlue.inc.c>